package cn.imust.www.finalapplication;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ListView;

import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.appindexing.Thing;
import com.google.android.gms.common.api.GoogleApiClient;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class MainActivity extends AppCompatActivity {

    private ListView listView;
    private EditText editeId;
    private EditText edType;
    private SQLiteDatabase db;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        listView = (ListView) findViewById(R.id.lv_show);
        editeId = (EditText) findViewById(R.id.it_id);
        edType = (EditText) findViewById(R.id.it_type);
        //添加两条数据
        MyOPenHeper myOPenHeper = new MyOPenHeper(getApplicationContext());
        db = myOPenHeper.getReadableDatabase();
        db.execSQL("insert into cdinfo(id,type)values(?,?)", new Object[]{"1", "zhangsan","2", "lisi"});
        listView.setAdapter(new MyAdapter());


    }


    class MyAdapter extends BaseAdapter {
        @Override
        public int getCount() {
            return 2;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view= View.inflate(getApplicationContext(), R.id.lv_show, null);

            Cursor cursor = db.query("select * from cdinfo ", null, null, null, null, null, null);

            while (cursor.moveToNext()){
                String id = cursor.getString(0);
                String type = cursor.getString(1);
                editeId.setText(id+"");
               edType.setText(type+"");
            }

            return view;
        }
    }
}
